package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.SysRole;
import com.easy.common.service.IRoleService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {
    @Autowired
    IRoleService roleService;
    @PostMapping("/")
    public ResultData insert(@RequestBody SysRole role){
        SysRole result=roleService.insert(role);
        return ResultData.success(result);
    }
    @PutMapping("/")
    public ResultData update(@RequestBody SysRole role){
        return ResultData.success(roleService.update(role));
    }
    @DeleteMapping("/{id}")
    public ResultData delete(@PathVariable Integer id){
        int result=roleService.delete(id);
        if(result>=1){
            return ResultData.success();
        }else{
            return ResultData.fail();
        }
    }
    @GetMapping("/{id}")
    public ResultData getByID(@PathVariable Integer id){
        return ResultData.success(roleService.getByID(id));
    }
    @GetMapping("/page")
    public ResultData getListByPage(IPage page,@RequestBody SysRole role){
        IPage<SysRole> data=roleService.getListByPage(page,role);
        return ResultData.success(data);
    }
    @GetMapping("/list")
    public ResultData getList(SysRole role){
        List<SysRole> data=roleService.getList(role);
        return ResultData.success(data);
    }
}
